<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">  

    <ui:composition template="/templates/templateCadastro.xhtml">

        <ui:define name="content">

            <h:form id="form" prependId="false">

                <p:growl showDetail="true" showSummary="true" autoUpdate="true" globalOnly="true" />

                <!-- INICIO CADASTRO -->

                <p:panel id="pnlCad" header="Cadastro de Cliente Jurídico" >

                    <h:panelGrid id="grid" columns="3" cellspacing="10">

                        <h:outputLabel value="Razão Social:" style="font-weight: bold"/>
                        <p:inputText id="razao" label="Razão Social" required="true" requiredMessage="Campo obrigatório" 
                                     title="Razão Social do Cliente Jurídico" value="#{clienteJuridicoBean.cliente.razaoSocial}" size="50" />
                        <p:message for="razao" />
                        
                        <h:outputLabel value="Nome Fantasia:" style="font-weight: bold"/>
                        <p:inputText id="nomeFantasia" label="Nome Fantasia" required="true" requiredMessage="Campo obrigatório" 
                                     title="Nome Fantasia do Cliente Jurídico" value="#{clienteJuridicoBean.cliente.nomeFantasia}" size="50" />
                        <p:message for="nomeFantasia" />
                        
                        <h:outputLabel value="CNPJ:"/>
                        <p:inputMask id="cnpj" label="CNPJ" mask="99.999.999/999-99"
                                     title="CNPJ do Cliente Jurídico" value="#{clienteJuridicoBean.cliente.cnpj}" size="50" />
                        <p:message for="cnpj" />

                        <h:outputLabel value="Inscrição Estadual:" />
                        <p:inputText id="inscEst" label="Inscrição Estadual" 
                                     title="Inscrição Estadual do Cliente Jurídico" value="#{clienteJuridicoBean.cliente.inscricaoEstadual}" size="50" />
                        <p:message for="inscEst" />

                        <h:outputLabel value="Telefone:" />
                        <p:inputMask id="tel" label="Telefone" mask="(99) 9999-9999"
                                     title="Telefone do Cliente Jurídico" value="#{clienteJuridicoBean.cliente.telefone}" size="50" />
                        <p:message for="tel" />

                        <h:outputLabel value="Responsável:" style="font-weight: bold" />
                        <p:inputText id="resp" label="Responsável" required="true" requiredMessage="Campo obrigatório" 
                                     title="Responsável do Cliente Jurídico" value="#{clienteJuridicoBean.cliente.responsavel}" size="50" />
                        <p:message for="resp" />

                        <h:outputLabel value="E-mail:" />
                        <p:inputText id="email" label="E-mail" validatorMessage="E-mail Inválido"
                                     title="E-mail do Cliente Jurídico" value="#{clienteJuridicoBean.cliente.email}" size="50" >
                            <f:validateRegex pattern="[\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]" />
                        </p:inputText>
                        <p:message for="email" />

                    </h:panelGrid>

                    <div style="text-align: center">

                        <p:commandButton value="Limpar" type="reset" icon="ui-icon-minusthick" />
                        <p:commandButton value="Cadastrar" actionListener="#{clienteJuridicoBean.cadastrar()}" rendered="#{clienteJuridicoBean.cadastro || clienteJuridicoBean.listagem}" icon="ui-icon-disk" update="@form" />
                        <p:commandButton value="Alterar" actionListener="#{clienteJuridicoBean.editar()}" rendered="#{clienteJuridicoBean.edicao}" icon="ui-icon-pencil" update="@form" />
                        <p:commandButton value="Cancelar" action="#{clienteJuridicoBean.cancelar()}" immediate="true" icon="ui-icon-cancel" />

                    </div>

                </p:panel>

                <!-- FIM CADASTRO -->

                <br />

                <!-- INICIO LISTAGEM -->

                <h:panelGroup id="tabela" >

                    <p:dataTable id="basic" var="item" value="#{clienteJuridicoBean.cliente}" emptyMessage="Nenhum Cliente Jurídico cadastrado até o momento"
                                 paginator="#{clienteJuridicoBean.paginator}" rows="#{clienteJuridicoBean.rowNumber}" >

                        <f:facet name="header">
                            Clientes Jurídicos
                        </f:facet>

                        <p:column headerText="Nome" sortBy="#{item.nomeFantasia}" style="width: 45%">
                            <h:outputText value="#{item.nomeFantasia}" />
                        </p:column>

                        <p:column headerText="Ação" style="text-align: center; width: 10%">
                            <h:commandButton id="edit" image="/resources/images/edit.png" actionListener="#{clienteJuridicoBean.prepararEditar()}" title="Clique para alterar">
                                <f:setPropertyActionListener value="#{item}" target="#{clienteJuridicoBean.cliente}" />
                                <f:ajax execute="@this" render="@form" />
                            </h:commandButton>
                            <p:tooltip for="edit" showEffect="slide" hideEffect="slide" />
                            &nbsp;
                            <h:commandButton id="remove" image="/resources/images/remove.png" action="#{clienteJuridicoBean.excluir()}" immediate="true" title="Clique para excluir">
                                <f:setPropertyActionListener value="#{item}" target="#{clienteJuridicoBean.cliente}" />
                            </h:commandButton>
                            <p:tooltip for="remove" showEffect="slide" hideEffect="slide" />
                        </p:column>

                    </p:dataTable>

                </h:panelGroup>

                <!-- FIM LISTAGEM -->

            </h:form>

        </ui:define>

    </ui:composition>

</html>